/**
 * In me the tiger sniffs the rose.
 *
 * @Author:徐家政
 * @Date:2019-04-19 09:06
 */
package com.shiyu.demo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shiyu.demo.entity.PostComment;
import com.shiyu.demo.mapper.PostCommentListMapper;
import com.shiyu.demo.service.PostCommentListService;
import com.shiyu.demo.util.ResultData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PostCommentListServiceImpl implements PostCommentListService {
    @Resource
    private PostCommentListMapper postCommentListMapper;
    @Override
    public ResultData getCommentList(Integer postId,Integer pageNum) {
        int size=2;
        if (pageNum<0) {
            pageNum = 0;
        }
        PageHelper.startPage(pageNum,size);
        List list=postCommentListMapper.getCommentList(postId);
        PageInfo info=new PageInfo(list);
        long total=info.getTotal();
        List list1=info.getList();
        ResultData resultData=new ResultData(total,list1);
        return resultData;
    }

    @Override
    public Integer updateCommentTop(Integer id) {
        return postCommentListMapper.updateCommentTop(id);
    }

    @Override
    public Integer addComment(Integer userId, String comment, Integer postId) {
        PostComment postComment=new PostComment();
        postComment.setUserid(userId);
        postComment.setComment(comment);
        postComment.setPostid(postId);
        return postCommentListMapper.addComment(postComment) ;
    }

}
